package com.bensonbasement.snorflux.client;

import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;

import com.bensonbasement.snorflux.client.states.CommandSelectState;
import com.bensonbasement.snorflux.commands.TargetMap;
import com.bensonbasement.snorflux.commands.VerbInfo;

public class VerbButton extends JButton {
	
	public VerbButton(final VerbInfo verb, int currentAP, final CommandSelectState callback) {
		super();
		boolean enabled = false;
		if (verb.isEnabled()) {
			int apCost = verb.getAPFormula().calculateAPCost(new TargetMap());
			if (currentAP >= apCost) {
				enabled = true;
			}
		}
		if (enabled) {
			this.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					callback.verbChosen(verb);
				}
			});
		}
		else {
			setEnabled(false);
		}
		ImageWarehouse warehouse = ImageWarehouse.getInstance();
		ImageIcon icon = new ImageIcon(warehouse.getImage(verb.getIconGlyph()));
		setIcon(icon);
		setToolTipText(verb.getName());
		setMargin(new Insets(0,0,0,0));
		setFocusable(false);
	}
}
